package com.ssm.pre.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ssm.pre.dao.FaultInfoDao;
import com.ssm.pre.service.FaultInfoService;
import com.ssm.pre.util.PageCount;
import com.ssm.pre.util.ToolUtil;
import com.ssm.util.object.InputObject;
import com.ssm.util.object.OutputObject;

@Service
public class FaultInfoServiceImpl implements FaultInfoService {

	@Autowired
	private FaultInfoDao fidao;

	@Override
	public void queryFaultInfoList(InputObject inputObject, OutputObject outputObject) throws Exception {
		Map<String, Object> map = inputObject.getParams();
		List<Map<String, Object>> beans = fidao.queryFaultInfoList(map);
		int page = Integer.parseInt(map.get("offset").toString())/Integer.parseInt(map.get("limit").toString());
		page++;
		List<Map<String, Object>> params = PageCount.page(beans, page, Integer.parseInt(map.get("limit").toString()));
		outputObject.setBeans(params);
		outputObject.settotal(beans.size()); 
	}

	@Override
	public void addFaultInfo(InputObject inputObject, OutputObject outputObject) throws Exception {
		Map<String, Object> map = inputObject.getParams();
			
		map.put("createId", inputObject.getLogParams().get("id"));
		map.put("createTime", ToolUtil.getTimeAndToString());
		int num = fidao.addFaultInfo(map);
		outputObject.settotal(num);

	}

	@Override
	public void editFaultInfo(InputObject inputObject, OutputObject outputObject) throws Exception {
		Map<String, Object> params = inputObject.getParams();
		params.put("createId", inputObject.getLogParams().get("id"));
		params.put("createTime", ToolUtil.getTimeAndToString());
		fidao.editFaultInfo(params);

	}

	@Override
	public void deleteFaultInfoById(InputObject inputObject, OutputObject outputObject) throws Exception {
		Map<String, Object> params = inputObject.getParams();
		int num = fidao.deleteFaultInfoById(params);
	
		outputObject.settotal(num);

	}

	@Override
	public void findFaultInfoById(InputObject inputObject, OutputObject outputObject) throws Exception {
		Map<String, Object> map = inputObject.getParams();
		Map<String, Object> bean = fidao.findFaultInfoById(map);
		outputObject.setBean(bean);
		
	}

}
